package com.tanhua.app.controllerservice;


import com.tanhua.api.db.UserInfoApi;
import com.tanhua.api.mongo.SoulTestApi;
import com.tanhua.domain.mongo.Answer;
import com.tanhua.domain.mongo.Report;
import com.tanhua.domain.mongo.SimilarYou;
import com.tanhua.domain.vo.ReportVo;
import com.tanhua.domain.vo.SoulVo;
import com.tanhua.domain.vo.UserHolder;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SoulTestService {
    @Reference
    private SoulTestApi soulTestApi;
    @Reference
    private UserInfoApi userInfoApi;
    public ResponseEntity testSoul(List<Answer> answers) {
        String id=soulTestApi.testSoul(answers, UserHolder.getUser().getId());
        return ResponseEntity.ok(id);
    }

    public ResponseEntity report(String pid) {
        Report report=soulTestApi.getReport(pid);
        ReportVo reportVo = new ReportVo(report);
        List<Long> similarYouIds = report.getSimilarYouIds();
        List<SimilarYou>similarYous=new ArrayList<>();
        for (Long id : similarYouIds) {
            SimilarYou similarYou = new SimilarYou();
            similarYou.setId(id);
            similarYou.setAvatar(userInfoApi.findUserInfo(id).getAvatar());
            similarYous.add(similarYou);
        }
        reportVo.setSimilarYou(similarYous);
        return ResponseEntity.ok(reportVo);

    }

    public ResponseEntity soulQuestion() {
        List<SoulVo> vos = soulTestApi.soulQuestion(UserHolder.getUser().getId());

        return ResponseEntity.ok(vos);
    }
}
